package com.zbec.mdrs.service;


import com.zbec.framework.core.service.SystemDictionaryService;
import com.zbec.framework.core.util.PageUtils;
import com.zbec.framework.core.vo.JqgridResponse;
import com.zbec.framework.core.vo.PageInfo;
import com.zbec.mdrs.constants.Constants;
import com.zbec.mdrs.entity.history.History;
import com.zbec.mdrs.repository.jpa.HistoryDao;
import com.zbec.mdrs.vo.HistoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * Created by fxl on 2015/10/18.
 */
@Component
@Transactional
public class HistoryService {

    private static Logger logger = LoggerFactory.getLogger(HistoryService.class);

    @Autowired
    private HistoryDao historyDao;

    @Autowired
    private SystemDictionaryService systemDictionaryService;

    public JqgridResponse<HistoryVo> findAllHistory(PageInfo pageInfo) {
        Page<HistoryVo> historyVoPage = historyDao.findAllHistory(PageUtils.buildPageRequest(pageInfo));
       packagingBean(historyVoPage.getContent());
        return PageUtils.buildResponse(historyVoPage, historyVoPage.getContent());
    }

    public void  packagingBean(List<HistoryVo> list){
        for (int i = 0; i <list.size() ; i++) {
            HistoryVo historyVo=list.get(i);
            historyVo.setBusinessTypeDesc(systemDictionaryService.getSystemDictionaryDesc(Constants.Constants_YWLX, historyVo.getBusinessType()));
        }
    }



}
